import Vue from 'vue'
import App from './App.vue'
import router from './router/'
import store from './store/'

import 'echarts'
import ECharts from 'vue-echarts'

import './element'
import './assets/style/reset.css'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/polar'
import 'echarts/lib/component/legend'
import 'echarts/lib/component/title.js'
import _ from 'lodash'
import { getDict } from '@/api/sys/dict'
import { getToken } from '@/utils/token'
import permission from './common/Permission'
import './common/dialog/dialogDrag'
import Ms from './common'

Vue.use(Ms)

Vue.component('v-chart', ECharts)
Vue.use(permission)
Vue.prototype._ = _
Vue.prototype.getDict = getDict
Vue.prototype.uploadUrl = process.env.NODE_ENV === 'web' ? `http://47.93.102.44:8080/vueManager/static/upload/` : `http://localhost:8080/vueManager/static/upload/`

// 路由守卫
router.beforeEach(async (to, form, next) => {
  if (to.path === '/') {
    next()
  } else {
    if (getToken()) {
      if (to.path === '/') {
        next('/layout')
      } else {
        if (store.state.user.userInfo === null) {
          // 获取用户所有状态信息 回调后跳转理由
          await store.dispatch('permission/generateRoutes').then(() => {
            next({ path: to.path })
          })
        } else {
          next()
        }
      }
    } else {
      next('/')
    }
  }
})

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
